package com.mall4j.cloud.leaf.controller;

import com.mall4j.cloud.leaf.core.common.Result;
import com.mall4j.cloud.leaf.service.SegmentService;
import com.mall4j.cloud.leaf.service.SnowflakeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;


@Tag(name = "获取分布式ID", description = "获取分布式ID")
@RestController
public class LeafController {

    @Resource
    private SegmentService segmentService;

    @Resource
    private SnowflakeService snowflakeService;

    @Operation(summary = "获取segment分布式ID", description = "获取segment分布式ID")
    @GetMapping(value = "/api/segment/get/{key}")
    public Long getSegmentId(@PathVariable("key") String key) {
        Result result = segmentService.getId(key);
        return result.getId();
    }

    @Operation(summary = "获取雪花分布式ID", description = "获取雪花分布式ID")
    @GetMapping(value = "/api/snowflake/get/{key}")
    public Long getSnowflakeId(@PathVariable("key") String key) {
        Result result = snowflakeService.getId(key);
        return result.getId();
    }

}
